﻿using UnityEngine;
using System.Collections;

public class JoyRot : MonoBehaviour {



	public  float joyPositionX;
	public  float joyPositionY;



	public CC  camScale;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnEnable()  
	{  
		EasyJoystick.On_JoystickMove += OnJoystickMove;  
		EasyJoystick.On_JoystickMoveEnd += OnJoystickMoveEnd;  
		
	} 
	//摇杆停止
	void OnJoystickMoveEnd(MovingJoystick move)  
	{  
		//没有移动摇杆
		if (move.joystickName == "joystickDir")  
		{  
			camScale.enabled=true;
		}
	}
	
	//移动摇杆中  
	void OnJoystickMove(MovingJoystick move)  
	{  
		//left
		
		if (move.joystickName != "joystickDir")  
		{  
			return;  
		}  
		
		//获取摇杆中心偏移的坐标  
		joyPositionX = move.joystickAxis.x;  
		joyPositionY = move.joystickAxis.y;  
		
		
		if (Mathf.Abs(joyPositionY) > 0.1f || Mathf.Abs(joyPositionX)> 0.1f)  
		{  
			camScale.enabled=false;

			//设置角色的朝向（朝向当前坐标+摇杆偏移量）  
			transform.LookAt(new Vector3(transform.position.x + joyPositionX, transform.position.y, transform.position.z + joyPositionY));  

		}
	}

}
